<template>
	<view>
		<form>
			<view class="cu-form-group margin-top">
				<view class="title">使用饲料</view>
				<input maxlength="12" type="text" placeholder="请输入使用的饲料" v-model="editor_feed_name" name="input" style="text-align: right;"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">使用量</view>
				<input maxlength="8" type="digit" placeholder="请输入使用量" v-model="editor_feed_number" name="input" style="text-align: right;"></input>
				<text style="font-size: 34rpx; margin-right: 10rpx;">KG</text>
			</view>
			<view class="cu-form-group">
				<view class="title">异常情况</view>
				<input maxlength="25" type="text" placeholder="请输入异常情况" v-model="editor_feed_abnormal_conditions" name="input" style="text-align: right;"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">饲料使用人联系电话</view>
				<input maxlength="11" type="number" placeholder="请输入联系电话" v-model="editor_feed_phone" name="input" style="text-align: right;"></input>
			</view>
		</form>
	</view>
</template>

<script>
	export default {
		data () {
			return {
				editor_feed_name: '',//使用饲料
				editor_feed_number: '',//使用量
				editor_feed_abnormal_conditions: '',//异常情况
				editor_feed_phone: '',//饲料使用人联系方式
				editor_feed_id: '',//饲料id
				
				feed_name: '',//使用饲料
				feed_number: '',//使用量
				feed_abnormal_conditions: '',//异常情况
				feed_phone: '',//饲料使用人联系方式
			}
		},
		onLoad(option) {
			console.log(option)
			this.editor_feed_name = option.editor_feed_name
			this.editor_feed_number = option.editor_feed_number
			this.editor_feed_abnormal_conditions = option.editor_feed_abnormal_conditions
			this.editor_feed_phone = option.editor_feed_phone
			this.editor_feed_id = option.editor_feed_id
			
			this.feed_name = option.editor_feed_name
			this.feed_number = option.editor_feed_number
			this.feed_abnormal_conditions = option.editor_feed_abnormal_conditions
			this.feed_phone = option.editor_feed_phone
			
		},
		onNavigationBarButtonTap() {
			this.save()
		},
		methods: {
			save () {
				
					var mobileReg=/^1[34578]\d{9}$/
					//console.log(this.User.token)
					if(this.editor_feed_name == this.feed_name &&
						this.editor_feed_number == this.feed_number &&
						this.editor_feed_abnormal_conditions == this.feed_abnormal_conditions &&
						this.editor_feed_phone == this.feed_phone) {
						
						uni.showToast({
							title:"您没有做任何修改哦",
							icon: "none"
						})
						return;	
					}
					else if(this.editor_feed_name.toString() === ""){
						uni.showToast({
							title:"请输入使用的饲料",
							icon: "none"
						})
						return;
					}
					else if(this.editor_feed_number.toString() === "" || this.editor_disinfection_number <= 0){
						uni.showToast({
							title:"请填写正确的使用量",
							icon: "none"
						})
						return;
					}
					else if(this.editor_feed_abnormal_conditions.toString() === ""){
						uni.showToast({
							title:"请输入异常情况",
							icon: "none"
						})
						return;
					}
					else if(!mobileReg.test(this.editor_feed_phone)){
						uni.showToast({
							title:"请填写正确的饲料使用人的联系电话",
							icon: "none"
						})
						return;
					}
					else{
						uni.request({
							url: this.confige.webUrl+'/livestock/updFeed',
							data: {
								feed_name: this.editor_feed_name,
								feed_number: this.editor_feed_number,
								feed_abnormal_conditions: this.editor_feed_abnormal_conditions,
								feed_phone: this.editor_feed_phone,
								feed_id: this.editor_feed_id
							},
							method:"POST",
							header: {
								"X-Token":this.User.token
							},
							success: (res) => {
								console.log(res)
								if(res.data.message == '更新成功！'){
									uni.showModal({
										title: "提示",
										showCancel: false,
										content: "修改成功",
										success: (res) => {
											if(res.confirm){
												uni.navigateBack({
													delta: 1
												})
											}
										}
									})	
								}
								else{
									uni.showModal({
										title: "提示",
										showCancel: false,
										content: res.data.message
									})
								}
							}
							
						})
					}	
			}
		}
	}
</script>

<style lang="less">
	@import "../../../common/main.css";
	
	.save {
		width: 710rpx;
		height: 80rpx;
		margin-top: 200rpx;
	}
	
	.save button {
		background-color: #4AC997;
		color: white;
		font-weight: bold;
		border-radius: 60rpx;
		margin-left: 40rpx;
		height: 80rpx;
		line-height: 80rpx;
	}
</style>
